-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Support Kafka Metrics for wrapped Kafka Clients #6267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Thanks for the issue!
I think For Other than these, I think there is a better solution to support other Kafka clients than making |
|
Hello @jonatan-ivanov, thank you for your response. Please let me know your thoughts. |
|
Thanks for the changes, I think I might have not been clear about this. Before even considering changing anything in Micrometer, I would like to explore the first two (preferred) options I mentioned above. |
|
Hi, I think it probably won't be possible to do that in fs2-kafka, but I may be wrong, it's worth asking. Let's see what we hear from the fs2-kafka developers. Regarding KAFKA-15191, I'm not a Kafka developer, I don't have an account :D |
Anyone can make an account. At the top of the page there should be a banner with the following message:
|
|
The fs2-kafka people don't seem to be very responsive. Are you still open to merging this PR @jonatan-ivanov ? |
Signed-off-by: Ondra Pelech <[email protected]>
|
I pinged them on the issue, I rebased your PR, added an extra ctor (we added one in the meantime), some javadoc and polished it. I think we can merge it either in |
|
So we have an answer from the fs2-kafka folks... What they say is true, you can hijack the underlying Java Kafka object during the creation. So it's technically possible. But I think that's a very in-elegant solution. I think adding more constructors to |
Signed-off-by: Ondra Pelech <[email protected]>
|
@jonatan-ivanov there are potential issues with concurrency when exposing the underlying clients from fs2-kafka. Are you OK with merging this PR? |
This is what dependency injection is all about unless I misunderstood something (my Scala fu is also ~10 years old).
Could you please elaborate on this? The underlying kafka client must be thread-safe otherwise we can throw out the whole support for it from Micrometer (Micrometer also calls the kafka client from its own thread). |
|
When we merge this PR, we'll be able to integrate Micrometer with fs2-kafka via the |
|
What concurrency issues would we face if we would not merge this in but we would use |
I'm not sure to be honest. But |
I'm not following. Why does that change anything compared to Micrometer receiving the client instance and calling the Kafka API for getting the metrics, as we do now in the constructors? Ultimately that KafkaMetrics is still calling the metrics API on the Kafka client, the same as we would, right? And that will happen at the same time as the client is being used by other threads, right? If there is a concurrency issue (I don't think there is), then it is an issue regardless.
More flexible has a nice nuance to it, but from the perspective of maintenance, we're going to need to support 4 new public constructors in a class that already has a lot of constructors and we are exposing what previously was an implementation detail as public API with this change. We don't want to support arbitrary maps of metrics from unknown sources - we want to support metrics from the official Kafka clients. It happens to be that your use case (probably) is ultimately sourcing them from the official Kafka client, but that's not enforced by the API proposed in this PR. At the end of the day, it probably won't be a big issue to add this, but it's not very enticing to open ourselves up to issues we don't have to deal with now. What does the alternative look like? How bad is it really to get the underlying client instance from the MkConsumer and MkProducer? |
|
The implementation of Indeed, you are correct that the new constructors in this PR don't enforce that the Metrics are coming from the Java Kafka client. But they give us more flexibility, which is something we'd be grateful for. Thank you 🙏 |
I can't understand why that would need to be the case. Can you point to some Kafka documentation explaining the concern for calling the Kafka client's |
|
I'm no Kafka expert, but the fs2-kafka maintainer @vlovgr has expressed concern about thread safety in this comment
|
|
I think the thread safety concerns of using the Kafka client for consuming messages from Kafka is different than retrieving metrics from the Kafka client, which is all Micrometer is concerned with doing. Somewhat tangentially, I've noticed today that Kafka has an interface MetricsReporter, and I wonder if we couldn't better instrument using that, which would require a rework of the KafkaMetrics, and would be another reason we would not want to add the constructors in this PR. It would take some more investigation to see if MetricsReporter does what we need or not, though. |
KafkaMetricsclass is currently package private. Making this public will enable using it in cases where constructingKafkaClientMetricsnorKafkaConsumerMetricsis a viable option.Specifically, when using fs2-kafka (a Scala library), where the access to the underlying Java Producer/Consumer isn't viable.
But the constructor of
KafkaMetricscan be satisfied even with fs2-kafka.